package com.zqh.irmadscore.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
//import com.zqh.irmadscore.mapper.TestMapper;
import com.zqh.irmadscore.service.TestService;
import com.zqh.irmadscore.mapper.TestMapper;
import com.zqh.irmadscore.model.entity.TestData;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.List;


@Service
@RequiredArgsConstructor
public class TestServiceImpl extends ServiceImpl<TestMapper, TestData>  implements TestService {


    private final TestMapper testMapper;

    @Override
    public List<TestData> getPageList() {

        // 构造分页参数（页码从 1 开始）
        Page<TestData> page = new Page<>(1, 10); // 当前页，每页数量

        // 写出 mybatis plus的  queryWrapper的方法
        LambdaQueryWrapper<TestData> queryWrapper = Wrappers.<TestData>lambdaQuery();
//        queryWrapper.eq(TestData::getMonitorType, "heartRate");


        // 执行分页查询（假设有 userMapper.selectPage 方法）
        Page<TestData> result = testMapper.selectPage(page, queryWrapper);

        // 获取结果
        List<TestData> records = result.getRecords(); // 当前页数据
        long total = result.getTotal();          // 总记录数
        long pages = result.getPages();           // 总页数

        System.out.println(total);
        System.out.println(pages);
        System.out.println(records);

        return records;
    }

    @Override
    public List<TestData> getAbnormalTestData(long minNum, long maxNum) {

        // 找到value小于minNum或者大于maxNum的值
        QueryWrapper<TestData> queryWrapper = new QueryWrapper<>();
        queryWrapper
                .and(i -> i.lt("value", minNum)
                        .or()
                        .gt("value", maxNum));


        return testMapper.selectList(queryWrapper);
    }
}
